/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.evolve.webbot.database;
import  java.io.File;
import  java.io.FileInputStream;
import  java.io.IOException;
import  java.sql.Connection;
import  java.sql.DriverManager;
import  java.sql.SQLException;
import  java.util.Properties;

/**
 *
 * @author DarthAE
 */

public class Conexion 
{
    private Connection con = null;
    
    public Conexion(String path)
    {
        con = creaConexion(path);
    }
    
    private Connection creaConexion(String path)
    {
        try{
            
            Properties      p   = new Properties();
            FileInputStream fis = new FileInputStream(path+File.separator+
                                                      "evolve-db.properties");
            p.load(fis);
            fis.close();
            
            Class.forName("org.gjt.mm.mysql.Driver");
            
            Connection con = DriverManager.getConnection(p.getProperty("db.url"),
                                                         p.getProperty("db.usr"),
                                                         p.getProperty("db.pwd"));
            p.clear();
            return con;
            
           }catch(IOException  ioex){}
            catch(ClassNotFoundException ex){}
            catch(SQLException sqlex){}
        
        return null;
    }
    
    public void closeConnection()
    {
        try{
            con.close();
           }catch(SQLException sqlex){}
    }
    
    public Connection getConnection()
    {
        return con;
    }
}
